package model

import (
	"github.com/gomodule/redigo/redis"
	"tizhi_front/nspel"
)

type Help struct {
	Id       int64  `gorm:"AUTO_INCREMENT;primary_key;column:id"`
	Question string `gorm:"column:question"`
	Answer   string `gorm:"column:answer"`
	Order    int64  `gorm:"column:order"`
}

func (h *Help) TableName() string {
	return "help"
}

type HelpE struct{}

func (h *HelpE) SelectAllOrderByOrderAsc() (helps []Help0, err error) {
	key := "help0.order.asc.all"
	err = nspel.RedisGetGob(key, &helps)
	if err == nil {
		return
	}
	if err != redis.ErrNil {
		nspel.Error(err)
	} else {
		err = nil
	}
	if err = nspel.GetOrm().Select([]string{"question", "answer"}).Order("order").Find(&helps).Error; err != nil {
		return
	}
	nspel.RedisSetGob(key, helps)
	return
}

type Help0 struct {
	Question string `gorm:"column:question"`
	Answer   string `gorm:"column:answer"`
}

func (h *Help0) TableName() string {
	return "help"
}
